Software Development
Reflection for Runtime Inspection
Java: Accessing Constructors, Methods, & Fields Using Reflection
Java: Getting Started with Reflection
Java: Leveraging Reflection to Build Dynamic Proxies & Unit Tests
Java: Working with Annotations, Generics, & Arrays Using Reflection

Java: Accessing Constructors, Methods, & Fields Using Reflection

Course Number:
it_jprfridj_02_enus
Lesson Objectives

Java: Accessing Constructors, Methods, & Fields Using Reflection

  • discover the key concepts covered in this course
  • access the constructors in a class using reflection
  • create objects of a class with handles to constructors
  • access member variables of a class and its metadata
  • access and update values of fields
  • access and update protected and private fields
  • access public, private, and protected methods
  • view method parameters, annotations, return types, and exceptions
  • view annotations on methods and recall the use of the retention policy
  • observe how not all annotations are available at runtime for reflective access
  • use method heuristics to identify getters and setters in a class
  • invoke and call methods using handles
  • summarize the key concepts covered in this course

Overview/Description
Reflective access allows a whole range of operations on objects that may not be permitted when you construct and use objects in the regular manner. This is extremely useful while building frameworks that may need access to the internals of your object. Use this course to extract information and metadata about the constructors in a class and use them, accessed via reflection, to instantiate objects. Access and modify fields or the member variables in an object. Access and invoke the methods defined on a class. Invoke static methods on the class itself and instance methods on specific objects of a class. When you're done, you'll have the ability to use reflection to access and work with all class members, whether they are fields, constructors, or methods.

Target

Prerequisites: none

Java: Getting Started with Reflection

Course Number:
it_jprfridj_01_enus
Lesson Objectives

Java: Getting Started with Reflection

  • discover the key concepts covered in this course
  • create and set up a basic IntelliJ project to write java code
  • define new classes and instantiate objects of these classes
  • use class handles accessed via reflection to explore properties of classes
  • view fields, methods, and their modifiers using reflection
  • examine how you can identify classes from their objects
  • use reflection to identify a variety of classes from objects
  • get fully qualified names and simple names of classes using their handles
  • investigate how you can get a handle to class objects using just the class name
  • use reflection to identify the modifiers of class members
  • identify anonymous, local, member classes, and interfaces using reflection
  • identify enums, arrays, and primitives using reflection
  • access package information, superclass, and declaring class information
  • summarize the key concepts covered in this course

Overview/Description
Reflection is a popular programming technique that accesses and modifies class and object information at runtime. Reflection is available in many programming languages, but Java has an especially powerful set of reflection APIs that reflect - no pun intended - the emphasis that Java lays on type safety. Learn how to access a Java class object. Use reflection APIs to view class fields, constructors, and methods. Create objects for various built-in classes and use reflection to view the class of an object. Investigate the significance of the fully qualified name of a class and how you can use the .forName() method from the built-in class java.lang.Class. Use this method to obtain variables of primitive types and arrays of differing dimensionality. Then use reflection to access modifiers applied to member fields. Upon completion, you'll be able to use reflection in your Java operations with confidence.

Target

Prerequisites: none

Java: Leveraging Reflection to Build Dynamic Proxies & Unit Tests

Course Number:
it_jprfridj_04_enus
Lesson Objectives

Java: Leveraging Reflection to Build Dynamic Proxies & Unit Tests

  • discover the key concepts covered in this course
  • implement a dynamic proxy to create a dynamic object implementing an interface
  • invoke interface methods and object base class methods on proxies
  • pass proxy method invocations to a real object
  • create annotations for the setup, teardown, and test case for a unit testing framework
  • annotate test case methods for unit testing
  • execute test cases using a custom test harness
  • summarize the key concepts covered in this course

Overview/Description
Reflection in Java is commonly used to create and use dynamic proxies, which allow you to create objects that implement one or more interfaces at runtime. Reflection is also used to build harnesses for unit testing frameworks to invoke set up and tear down methods and run tests. Use this course to get to grips with these use cases. Work with and learn why dynamic proxies are incredibly powerful. Investigate what happens to methods you invoke on an instance of a dynamic proxy class. Then create a unit-testing framework harness similar to the JUnit framework in Java. Use annotations to identify methods and mark tests to run before using reflection to identify them and run them in the correct sequence. When you're finished, you'll have the ability to use reflection to create dynamic proxies and build harnesses for unit test frameworks.

Target

Prerequisites: none

Java: Working with Annotations, Generics, & Arrays Using Reflection

Course Number:
it_jprfridj_03_enus
Lesson Objectives

Java: Working with Annotations, Generics, & Arrays Using Reflection

  • discover the key concepts covered in this course
  • examine what built-in annotations are accessible using reflection
  • create a custom annotation and examine retention policies
  • implement a use-case for reflection - accessing annotations to perform checks
  • implement a use-case for reflection - using reflection to check the objects of classes for validity
  • identify what generic information about type parameters is available using reflection
  • explore the disadvantages of using reflection with generics
  • view and edit data stored in arrays
  • use reflective access to determine array types and component types
  • summarize the key concepts covered in this course

Overview/Description
Annotations on Java code allow you to associate additional metadata with classes, member variables, constructors, and methods. These annotations can be used to perform additional checks or add functionality to your Java code. Use this course to practice using annotations with reflection. Work with both built-in and custom annotations and see how you can access the annotations applied on classes, fields, and methods. Learn why not all annotations can be accessed via reflection. Create your own custom annotation and experiment with various retention policies. Next, examine accessing generics and arrays with reflection. When you're finished, you'll be able to harness the power of reflection to add new functionality to your code and work with generics and arrays.

Target

Prerequisites: none

Close Chat Live